package weaver.interfaces.suntai.utils;

import com.alibaba.fastjson.JSONObject;
import weaver.general.Util;
import weaver.interfaces.suntai.constant.Constant;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-05-11
 * @Description: 一体化合同管理系统上报数据接口
 * @ModifyLog:
 **/

public class InvokeHelper {

    private static Map map = new HashMap();
    static {
        map.put(Constant.Token, "token/getToken");
        map.put(Constant.Sellcont, "api/sellcont/insert");
        map.put(Constant.BatchSellcont, "api/sellcont/insertList");
        map.put(Constant.ChangeSellcont, "api/change/insert");
        map.put(Constant.BatchChangeSellcont, "api/change/insertList");
        map.put(Constant.Paycont, "api/paycont/insert");
        map.put(Constant.BatchPaycont, "api/paycont/insertList");
        map.put(Constant.Income, "api/income/insert");
        map.put(Constant.Proceeds, "api/proceeds/insert");
    }

    /**
     * @Description: 获取token
     * @Param: []
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String getToken() {
        String url = Constant.URL+map.get("Token");
        Map<String, String> param = new HashMap<>();
        param.put( "key", Constant.KEY );
        String resultText = HttpUtil.httpGet( url, param );
        JSONObject resultJson = JSONObject.parseObject(resultText);
        String data = Util.null2String(resultJson.getString( "data" ));
        return data;
    }

    public static String Invoke(String type,String params){
        String url = Constant.URL+map.get(type);
        Map<String, String> header = new HashMap<>();
        header.put( "ContentType", "application/json" );
        String token = getToken();
        header.put( "token", token );
        String ecode = "UTF-8";
        return HttpUtil.httpPostRaw( url, params, header, ecode );
    }
    /**
     * @Description: 新增销售合同信息
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addSellcont(String params) {
        return Invoke(Constant.Sellcont, params);
    }

    /**
     * @Description: 批量新增销售合同信息
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addBatchSellcont(String params) {
        return Invoke(Constant.BatchSellcont, params);
    }

    /**
     * @Description: 新增销售合同变更信息
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addChangeSellcont(String params) {
        return Invoke(Constant.ChangeSellcont, params);
    }

    /**
     * @Description: 批量新增销售合同变更信息
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addBatchChangeSellcont(String params) {
        return Invoke(Constant.BatchChangeSellcont, params);
    }
    /**
     * @Description: 新增采购合同信息
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addPaycont(String params) {
        return Invoke(Constant.Paycont, params);
    }
    /**
     * @Description: 合同收入新增接口
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addIncomecont(String params) {
        return Invoke(Constant.Income, params);
    }
    /**
     * @Description: 合同收款新增接口
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addProceedscont(String params) {
        return Invoke(Constant.Proceeds, params);
    }
    /**
     * @Description: 批量新增采购合同信息
     * @Param: [params]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/5/11
     */
    public static String addBatchPaycont(String params) {
        return Invoke(Constant.BatchPaycont, params);
    }
}
